package com.example.tbplus14.Test;

public class LockTest {

    public synchronized void method() {
        System.out.println(Thread.currentThread().getName() + " acquired the lock");
        try {
            Thread.sleep(1000); // 模拟操作
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        LockTest example = new LockTest();

        // 启动多个线程来模拟锁竞争
        for (int i = 0; i < 5; i++) {
            new Thread(example::method).start();
        }
    }

}
